let mytimeout = null;
let file = null;
var vm = new Vue({
  el: "#app",
  data: {
    hasSelectFile: false,
    state: 'ready',
    per: 0
  },
  beforeMount: function () {

  },
  methods: {
    onFileChange() {
      let that = this;
      let selector = document.querySelector("#file");
      if (selector.files.length > 0) {
        that.hasSelectFile = true;
        file = selector.files[0];
        that.state = 'ready';
        console.log('has select file', file)
      } else {
        that.hasSelectFile = false;
        file = null;
      }
    },
    onStart() {
      let that = this;
      if (!this.hasSelectFile) return;
      uploader.start(file, function (state, per) {
        that.state = state;
        that.per = per;
        console.log(that.per);
      });
    },
    onPause() {
      uploader.pause();
    },
    onResume() {
      uploader.resume();
    },
    onCancel() {
      this.hasSelectFile = false;
      uploader.cancel();
    }
  }
});